// 输入框组件实例

import { assignInWith } from 'lodash'
import type { inputConfigType, rateConfigType } from '../../../../../types/index'
import BaseEntity from '../../BaseEntity'
import { uid } from 'uid'
import type { configType, slotFormConfigType } from '../../BaseEntity'
import { entityType } from '../..'
export default class RateEntity extends BaseEntity {
    constructor(config: configType, slotFormConfig: slotFormConfigType) {
        let baseConfig: configType = {
            class: ['draggable-form-hover'],
            style: { width: '100%' },
            field: 'Rate_' + uid(4),
            label: '评分',
            hideLabel: false,
            required: false
        }
        let baseSlotFormConfig: slotFormConfigType = {
            modelValue: 0,
            allowClear: false,
            count: 5,
            grading: false,
            allowHalf: false,
        }
        let componentConfig: rateConfigType = {
            allowClear: {
                type: 'switch',
                formItemConfig: {
                    label: '是否允许清除'
                },
                formItemElement: {
                    modelValue: false,
                }
            },
            allowHalf: {
                type: 'switch',
                formItemConfig: {
                    label: '是否开启半选'
                },
                formItemElement: {
                    modelValue: false
                }
            },
            count: {
                type: 'inputNumber',
                formItemConfig: {
                    label: '最大评分数'
                },
                formItemElement: {
                    modelValue: 0,
                    placeholder: '请输入最大评分数量'
                }
            },
            grading: {
                type: 'switch',
                formItemConfig: {
                    label: '是否开启笑脸分级'
                },
                formItemElement: {
                    modelValue: false
                }
            }
        }

        super(
            entityType.rate,
            assignInWith(baseConfig, config),
            assignInWith(baseSlotFormConfig, slotFormConfig),
            componentConfig
        )
        this.initSlotFormConfig()
    }
    initSlotFormConfig() {
         //初始化表单组件可配置项 因为表单组件可配置项是根据表单组件所拥有得属性来定义的 配置项得值需要对应初始化实例得对应属性得值
         Object.keys(this.componentConfig).forEach(key => {
          if (this.slotFormConfig[key]) {
              this.componentConfig[key].formItemElement.modelValue = this.slotFormConfig[key]
          }
      })
    }
}
